package com.itheima.序列化流.写读集合;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class ConvertedDemo7 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        Student s1 = new Student("abc", 17);
        Student s2 = new Student("def", 18);
        Student s3 = new Student("ghi", 19);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day623-24CharStream\\xx.txt"));

        ArrayList<Student> list = new ArrayList<>();
        Collections.addAll(list, s1, s2, s3);

        //往本地文件写入一个集合
        oos.writeObject(list);
        oos.close();

        //读取集合
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day623-24CharStream\\xx.txt"));
        ArrayList<Student> list2 = (ArrayList<Student>) ois.readObject();
        for (Student student : list2) {
            System.out.println(student);
        }
        ois.close();

    }

}
